Introduction to R/RStudio
Welcome!
Download R and RStudio
- Download R → https://www.r-project.org/
- Download RStudio →
https://rstudio.com/products/rstudio/download/
- See ELMS for instructions
What is R?
What is R?
“R is a language and environment for
statistical computing and graphics.”
- Where you write code
- What language you write code in
What is RStudio?
“An integrated development
environment for R
- Where you write code
Both use R as
the coding
language
Both use English
as the language
Basically, download both
R & RStudio
but we will mainly use
RStudio
Why learn programming?
- Make life easier
- Analysis
- Generate pretty
graphics
Other fun/irrelevant uses
- Generate random cat fact
- Generate random noises
- Play rap music
- Tweet
- Order an Uber
Syllabus
General Information
- No programming experience required
- No textbook required
- See syllabus for online resources
- Google is your friend
- Slides, lecture code, datasets will be posted
Topics
- Syntax
- Functions
- Data manipulation
- Modeling
- Statistical significance
- Figures
- Packages
This class is a mix of subjects
- Biology
- Examples we do will be applications of biology
- Statistics
- Some basic statistics (p-values, linear regression, t-
test)
- Computer programming
Programming 101
- Many coding languages
- R is one language
- Write code in sc ript
- Instructions telling computer what to do
- Run script
- Computer produces output in console
Genetic code
in nucleus
tells cell what
to do
Output: proteins
Computer code
in script tells
computer what
to do
Output: values
All code is written in a script
Can change the view
Editor vs Console
Run Code
Save your code!
All code is written in a script
Editor vs Console
Run Code
Save your code!
Misc
- You can code directly into console
- Commands will be preceded by “>”
- But want to save code together
- Save your script so you can reuse it!
Open previous scripts
Open previous scripts
Helpful shortcuts
- Ctrl+S/Cmd+S: save code
- Ctrl+L: clears console
- Ctrl+R: run in R
- Ctrl+Enter/Cmd+Return: run in RStudio
- Ctrl+O/Cmd+O: open previous script
- https://support.rstudio.com/hc/en-us/articles/200711853-
Keyboard-Shortcuts
Lesson 1: Commenting
- Used to explain what’s going on in your code (English)
- Computer ignores these
- Each line preceded by #
- #This is a comment
Your turn: First In-Class Exercise
- Submit to ELMS the following information as comments
- #Name:
- #Year:
- #Major:
- #Programming/statistics experience?
- #Anything you wish to let me know about yourself